package com.javasm.service.goodsService.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.common.page.PageResult;
import com.javasm.domin.criteria.goodsCriteria.PaPriceAdministrationCriteria;
import com.javasm.domin.entity.goodsEntity.PaPriceAdministration;
import com.javasm.domin.vo.goodsVo.PaPriceAdministrationVo;
import com.javasm.mapper.goodsMapper.PaPriceAdministrationMapper;
import com.javasm.service.goodsService.PaPriceAdministrationService;
import com.javasm.transfer.goodsTransfer.PaPriceAdministrationTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
* @author Administrator
* @description 针对表【pa_price_administration】的数据库操作Service实现
* @createDate 2021-11-24 21:46:49
*/
@Service
@Transactional
@RequiredArgsConstructor
public class PaPriceAdministrationServiceImpl extends ServiceImpl<PaPriceAdministrationMapper, PaPriceAdministration>
implements PaPriceAdministrationService {



    @Autowired
    public PaPriceAdministrationMapper paPriceAdministrationMapper;

    @Autowired
    public PaPriceAdministrationTransfer paPriceAdministrationTransfer;


    @Override
    public PageResult<PaPriceAdministrationVo> searchPage(PaPriceAdministrationCriteria paPriceAdministrationCriteria) {

        String goodsName = paPriceAdministrationCriteria.getGoodsName();
        String auditStatus = paPriceAdministrationCriteria.getAuditStatus();
        String teffectiveTime = paPriceAdministrationCriteria.getTeffectiveTime();
        String invalidTime = paPriceAdministrationCriteria.getInvalidTime();

        LambdaQueryWrapper<PaPriceAdministration> lambda = new QueryWrapper<PaPriceAdministration>().lambda();

        if (!StringUtils.isEmpty(goodsName)){
            lambda.like(PaPriceAdministration::getGoodsName,goodsName);
        }
        if (!StringUtils.isEmpty(auditStatus)){
            lambda.like(PaPriceAdministration::getAuditStatus,auditStatus);
        }
        if (!StringUtils.isEmpty(teffectiveTime)){
            lambda.eq(PaPriceAdministration::getTeffectiveTime,teffectiveTime);
        }
        if (!StringUtils.isEmpty(invalidTime)){
            lambda.eq(PaPriceAdministration::getInvalidTime,invalidTime);
        }

        PageHelper.startPage(paPriceAdministrationCriteria.getCurrentPage(),paPriceAdministrationCriteria.getPageSize());

        List<PaPriceAdministration> paPriceAdministrations = paPriceAdministrationMapper.selectList(lambda);

        PageInfo<PaPriceAdministration> paPriceAdministrationPageInfo = new PageInfo<>(paPriceAdministrations);

        long total = paPriceAdministrationPageInfo.getTotal();

        List<PaPriceAdministrationVo> paPriceAdministrationVos = paPriceAdministrationTransfer.toVO(paPriceAdministrations);

        return new PageResult<PaPriceAdministrationVo>(total,paPriceAdministrationVos);
    }

    @Override
    public int batchDeleteIds(List<Long> ids) {
        return paPriceAdministrationMapper.deleteBatchIds(ids);
    }
}
